package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.utils.StringUtils;
import com.example.demo.dbo.User;
import com.example.demo.entity.LotteryRedisData;
import com.example.demo.entity.LotteryRedisDataVO;
import com.example.demo.entity.TUser;
import com.example.demo.enums.CollectNeedSameTimeEnum;
import com.example.demo.service.TUserService;
import com.google.gson.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @Classname DemoController
 * @Description TODO
 * @Date 2019/10/15 10:48
 * @Created by yby
 */
@RestController
@RequestMapping("/yby")
public class DemoController {

    private static final Logger logger = LoggerFactory.getLogger(DemoController.class);

    @Autowired
    private TUserService tUserService;

    @RequestMapping("/insert")
    public void insertData(@RequestBody TUser tuser, String name){
        logger.info("tuser:{},name:{}",JSONObject.toJSONString(tuser),name);
        System.out.println("insert ...");
        tUserService.addData(tuser);
    }

    @RequestMapping("/speak")
    public LotteryRedisDataVO speak(){
        /*System.out.println("测试mvc接口");
        LotteryRedisData lotteryRedisData=new LotteryRedisData();
        lotteryRedisData.setCpOdd("10000A");
        lotteryRedisData.setStatus("online");
        lotteryRedisData.setId(123456L);
        lotteryRedisData.setLastUpdateTime(124556L);
        LotteryRedisDataVO vo=new LotteryRedisDataVO();
        BeanUtils.copyProperties(lotteryRedisData, vo);
        vo.setByteStatus(356);
        vo.setByteStatus(1);
        if(vo.getByteStatus() == 1){
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("print1","硬件1未连接");
            jsonObject.put("print2","硬件2未连接");
            jsonObject.put("print","打印机故障");
            vo.setByteStatusDetail(jsonObject.toJSONString());
        }
        System.out.println(vo.toString());

        if(vo.getByteStatus() !=1 && vo.getByteStatus() !=0){
            System.out.println("我不是1哦");
        }*/

        return null;


    }


    public static void main(String[] args) throws InterruptedException {

        /*long start = System.currentTimeMillis();
        Thread.sleep(6000);
        long end =System.currentTimeMillis();
        LOG.info("数字"+(end-start)+"ms");
        long minutes = ((end-start) % (1000 * 60 * 60)) / (1000 * 60);
        System.out.println(minutes);*/
        List<String>  list =new ArrayList<>();
        list.add("1111");
        list.add("2222");
        list.add("3333");
        list.add("4444");
        list.add("5555");
       /* DemoController DemoController =new DemoController();
        DemoController.speak(list);
        DemoController.say(list);*/
        // 获取主机/辅机 个数
        Map<String, String> enumMap = CollectNeedSameTimeEnum.getKeysAndDeviceCode();
        Iterator<Map.Entry<String, String>> iterator = enumMap.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<String, String> entry = iterator.next();
            // 通用的 需要根据个数进行转换 如主机/辅机
            System.out.println("entry.getValue()="+entry.getValue());
            System.out.println("entry.getKey()="+entry.getKey());
        }
        System.out.println(enumMap.toString());

    }

    @Async
    public void say(List<String> list) {
        System.out.println("say="+list.toString());
    }

    @Async
    public  void speak(List<String> list) {

        list.remove("5555");
        list.add("6666");
        System.out.println("speak="+list);
    }


}